package com.crscd.jdbc.senior.dao.impl;

import com.crscd.jdbc.senior.dao.BankDao;
import com.crscd.jdbc.senior.dao.BaseDao;

import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 10/23/25 3:28 PM
 * @modifiedBy:
 * @version: 1.0
 */
public class BankDaoImpl extends BaseDao implements BankDao {
  @Override
  public int addMoney(Integer id, Integer money) {
    final String sql = "update t_bank set money=money+? where id=?";
    try {
      return executeUpdate(sql, money, id);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }

  @Override
  public int subMoney(Integer id, Integer money) {
    final String sql = "update t_bank set money=money-? where id=?";
    try {
      return executeUpdate(sql, money, id);
    } catch (SQLException e) {
      throw new RuntimeException(e);
    }
  }
}
